import time
import threading
from concurrent.futures import ThreadPoolExecutor, as_completed
import os
import os,datetime

import pandas as pd
__path="E:\\testfile\\"
starttime = datetime.datetime.now()
__listdir = os.listdir(__path)
def sayhello(name):
    # print("%s say Hello to %s" % (threading.current_thread().getName(), name));
    # time.sleep(1)
    pd.read_table(os.path.join(__path,name),encoding="GBK")
    return "["+threading.current_thread().getName() +"]"+name

name_list =__listdir #["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] #['admin','root','scott','tiger']
# start_time = time.time()
with ThreadPoolExecutor(200) as executor: # 创建 ThreadPoolExecutor
    future_list = [executor.submit(sayhello, name) for name in name_list] # 提交任务

# endtime = datetime.datetime.now()
# print('程序运行时间:' + str(endtime - starttime))
# os.system("pause")
for future in as_completed(future_list):
    result = future.result() # 获取任务结果
    print("%s get result : %s" % (threading.current_thread().getName(), result))

#print('%s cost %d second' % (threading.current_thread().getName(), time.time()-start_time))
endtime = datetime.datetime.now()
print('程序运行时间:' + str(endtime - starttime))
#
# ## 运行结果如下
# ThreadPoolExecutor-0_0 say Hello to admin
# ThreadPoolExecutor-0_1 say Hello to root
# ThreadPoolExecutor-0_0 say Hello to scott
# ThreadPoolExecutor-0_1 say Hello to tiger
# MainThread get result : root
# MainThread get result : tiger
# MainThread get result : scott
# MainThread get result : admin
# MainThread cost 2 second